package com.wcj.sort;

public class 插入排序 {

    public static void main(String[] args) {
        int[] arr = new int[]{23,12,36,451,2,89,78,54};
        insertSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void insertSort(int[] arr){
        int j;
        for (int i = 1; i < arr.length; i++){
            int tmp = arr[i];
            for (j = i; j > 0 && tmp<arr[j-1];j--){
                arr[j] = arr[j - 1];
            }
            if (j != i){
                arr[j] = tmp;
            }
        }
    }
}
